package org.xiangfei.client.handler;

import java.util.logging.Level;
import java.util.logging.Logger;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.xiangfei.client.XFCallback;
import org.xiangfei.codec.bean.XFMessage;
public class MessageClientHandler extends SimpleChannelInboundHandler<XFMessage> {
    private XFCallback callback;
    public MessageClientHandler(XFCallback callback) {
        this.callback = callback;
    }
    private Logger logger=Logger.getLogger(MessageClientHandler.class.getName());

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        try {
            logger.log(Level.INFO, "初始化一个客户端");
        }catch(Exception e) {
            e.printStackTrace();
        }
    }

    public void channelRead0(ChannelHandlerContext ctx, XFMessage message) throws Exception {
        
        System.out.println("client接收到服务器返回的消息:" + message.getMessage() + "=" + callback);
        callback.messageArrived(message);
        //System.out.println("response: code="+response.getResultCode()+", message="+response.getResultMessage());
        //ctx.close();
    }

    

   
}